﻿@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'commonTable', 'common', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table, commonTable = layui.commonTable,
            common = layui.common;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        $("#F_CheckType").bindSelect({
            data: top.clients.dataItems['Mes_CheckType'],
            id: "",
        });
        $("#F_MaterialType").bindSelect({
            data: top.clients.dataItems['Mes_MaterialType'],
            id: "",
        });
        commonTable.rendertable({
            elem: '#currentTableId',
            id: 'currentTableId',
            search: false,
            limit: 9999,//每页数据 默认
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count'] //自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            defaultToolbar: [],
            toolbar: '',//工具栏
            data: [],
            height: 'full-220',
            cols: [[
                { field: 'F_Description', title: '缺陷说明', minWidth: 170, sort: true },
                {
                    field: 'F_FilePath', title: '缺陷图片', minWidth: 150,
                    templet: function (d) {
                        if (!!d.F_FilePath) {
                            return '<img src="' + d.F_FilePath + '" style="height: 25px; width: 25px; line-height: 25 px!important;" onclick="previewImg(this)">'
                        }
                        else {
                            return '';
                        }
                    }
                },
                {
                    field: 'F_FilePath', title: '图片下载', width: 105,
                    templet: function (d) {
                        return '<a href="' + d.F_FilePath + '" download="' + new Date().Format("yyyyMMddhhmmss")+'" class="layui-btn layui-btn-sm layui-btn-normal">下载</a >'
                    }
                },
            ]]
        });
        $(function () {
            common.ajax({
                url: '/QualityManage/ScapMaterial/GetFormJson',
                dataType: 'json',
                data: { keyValue: keyValue },
                async: false,
                success: function (data) {
                    common.val('adminform', data);
                    common.setReadOnly('adminform');
                    if (!!data.list && data.list.length > 0) {
                        table.reload('currentTableId', {
                            data: data.list
                        });
                    }
                    form.render();
                }
            });
        });
        wcLoading.close();
    });
    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var height = img.height + 50; //获取图片高度
        var width = img.width; //获取图片宽度
        if (height > 500) { height = 500; };
        if (width > 500) { width = 500; };
        var imgHtml = "<img src='" + obj.src + "' style=\"height: " + (height - 43) + "px; width: " + width + "px; line-height: 25px!important;\"/>";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [width + 'px', height + 'px'],
            shadeClose: true,//点击外围关闭弹窗
            scrollbar: false,//不现实滚动条
            title: "图片预览", //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
    function download(obj) {
        var url = obj.src;                            // 获取图片地址
        var a = document.createElement('a');          // 创建一个a节点插入的document
        var event = new MouseEvent('click')           // 模拟鼠标click点击事件
        a.download = 'beautifulGirl'                  // 设置a节点的download属性值
        a.href = url;                                 // 将图片的src赋值给a节点的href
        a.dispatchEvent(event)
    }
</script>

<body>
    <div class="layuimini-container" lay-filter="adminform">
        <div class="layuimini-main">
            <form class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">检验类型</label>
                        <div class="layui-input-block">
                            <select id="F_CheckType" name="F_CheckType" lay-search>
                                <option value="" selected>请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">条码编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_BatchCode" name="F_BatchCode" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">物料编号</label>
                        <div class="layui-input-block">
                            <input id="F_MaterialCode" name="F_MaterialCode" type="text" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">物料名称</label>
                        <div class="layui-input-block">
                            <input id="F_MaterialName" name="F_MaterialName" type="text" class="layui-input" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">物料分类</label>
                        <div class="layui-input-block">
                            <select id="F_MaterialType" name="F_MaterialType" lay-search>
                                <option value="" selected>请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">可疑数量</label>
                        <div class="layui-input-block">
                            <input id="F_Num" name="F_Num" type="text" class="layui-input" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">报废数量</label>
                        <div class="layui-input-block">
                            <input id="F_ScapNum" name="F_ScapNum" type="text" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">退回数量</label>
                        <div class="layui-input-block">
                            <input id="F_ReturnNum" name="F_ReturnNum" type="text" class="layui-input" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">缺陷列表</label>
                        <div class="layui-input-block">
                            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>

